/*
 *    This program is free software; you can redistribute it and/or modify
 *    it under the terms of the GNU General Public License as published by
 *    the Free Software Foundation; either version 2 of the License, or
 *    (at your option) any later version.
 *
 *    This program is distributed in the hope that it will be useful,
 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *    GNU General Public License for more details.
 *
 *    You should have received a copy of the GNU General Public License
 *    along with this program; if not, write to the Free Software
 *    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 *
 *    2011 year
 *    Author: Michael Khromov aka MikeDM (Mike D'Morto)
 *    E-Mail: mikedmorto@gmail.com
 */

#include "coredialog.h"
#include "ui_coredialog.h"
#include <QDesktopWidget>
#include <QMessageBox>
#include <QFile>
#include <QPluginLoader>
#include <QListWidgetItem>

CoreDialog::CoreDialog(QList<iWorker*> * workerListd, QWidget *parent) :
    QDialog(parent),
    ui(new Ui::CoreDialog)
{
    ui->setupUi(this);
    this->workerList = workerListd;
    // добавляем кнопку минимизации окна.
    this->setWindowFlags(Qt::WindowMinMaxButtonsHint);
    this->move(QApplication::desktop()->availableGeometry(this).center()-rect().center());
    for(int i = 0 ; i < this->workerList->size() ; i++){
        QListWidgetItem * item = new QListWidgetItem(this->workerList->at(i)->getPluginName());
        item->setIcon(this->workerList->at(i)->getPluginIcon());
        this->ui->listWidget->addItem(item);
    }    
    //this->ui->listWidget->setViewMode(QListWidget::IconMode);
    this->ui->listWidget->setIconSize(QSize(24,24));
    connect(this->ui->listWidget,SIGNAL(clicked(QModelIndex)),this,SLOT(slotItemCliced()));
}

void CoreDialog::slotItemCliced(){
    // два раза щелкнули по итему. тут то мы и дергаем экзек метод плагина по номеру
    qDebug()<<"Current inrem row estas "<<this->ui->listWidget->currentRow();
    //this->setVisible(false);
    qDebug()<<"RRR "<< this->workerList->at(this->ui->listWidget->currentRow())->exec();
    //this->setVisible(true);
}


CoreDialog::~CoreDialog()
{
    delete ui;
}

